<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增标记记录')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-markerrecord-add">
            <div class="form-group">    
                <label class="col-sm-3 control-label">标记类别：</label>
                <div class="col-sm-8">
                    <select name="markerId" class="form-control m-b">
                        <option th:each="marker : ${gisMarkerList}" th:text="${marker.markerName}" th:value="${marker.Id}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">地点名称：</label>
                <div class="col-sm-8">
                    <input name="recordName" class="form-control recordName" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">所属省：</label>
                <div class="col-sm-8">
                    <select name="province" class="form-control m-b" id="provinceSelector">
                        <option value="">所有</option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">所属市：</label>
                <div class="col-sm-8">
                    <select name="city" class="form-control m-b" id="citySelector">
                        <option value="">所有</option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">所属县：</label>
                <div class="col-sm-8">
                    <select name="county" class="form-control m-b" id="countySelector">
                        <option value="">所有</option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">经度：</label>
                <div class="col-sm-8">
                    <input name="longitude" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">维度：</label>
                <div class="col-sm-8">
                    <input name="latitude" class="form-control" type="text">
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <!--引入城市信息JS-->
    <script th:src="@{/js/locationInfo.js}"></script>
    <script th:inline="javascript">
        var prefix = ctx + "gis/markerrecord"

        //城市三级选择器
        var current_prov; //当前省
        var current_city; //当前市
        var current_county; //当前县

        $("#form-markerrecord-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-markerrecord-add').serialize());
            }
        }

        /*初始化省份列表*/
        function initProvince(){
            console.log("加载省份列表");
            var provinceInfo = locationInfo;
            provinceInfo.forEach(function(currentValue, index, arr){
                $('#provinceSelector')
                    .append("<option value='"+currentValue.name+"' index='"+index+"'>"+currentValue.name+"</option>");
            })
            /*设置select选择方法*/
            $('#provinceSelector').change(function () {
                current_prov = $('#provinceSelector option:selected').attr('index');
                initCity();
            })
        }

        /*初始化城市列表*/
        function initCity(){
            console.log("加载城市列表");
            var cityInfo = locationInfo[current_prov].city;
            /*清除之前option*/
            $('#citySelector option').remove();
            $('#citySelector').append("<option>所有</option>");
            cityInfo.forEach(function(currentValue, index, arr){
                /*添加新的option*/
                $('#citySelector')
                    .append("<option value='"+currentValue.name+"' index='"+index+"'>"+currentValue.name+"</option>");
            })
            /*设置select选择方法*/
            $('#citySelector').change(function () {
                current_city = $('#citySelector option:selected').attr('index');
                initCounty();
            })
        }

        /*初始化县区列表*/
        function initCounty() {
            console.log("加载县区列表");
            var countyinfo = locationInfo[current_prov].city[current_city];
            /*判断是否有下一级菜单*/
            if(countyinfo.hasOwnProperty('area')){
                $('#countySelector').parent().parent().show();
                countyinfo = locationInfo[current_prov].city[current_city].area;
                /*清除之前option*/
                $('#countySelector option').remove();
                $('#countySelector').append("<option>所有</option>");
                countyinfo.forEach(function(currentValue, index, arr){
                    /*添加新的option*/
                    $('#countySelector')
                        .append("<option value='"+currentValue+"' index='"+index+"'>"+currentValue+"</option>");
                })
                /*设置select选择方法*/
                $('#countySelector').change(function () {
                    current_county = $('#countySelector option:selected').attr('index');
                })
            }
            else{
                $('#countySelector').parent().parent().hide();
            }
        }
        initProvince();
        $.ajax(
            {
                type: "POST",
                url: prefix+"/list",
                success: function(data){
                    console.log(data);
                },
                error: function(){
                    alert("查询失败");
                }
            });
    </script>
</body>
</html>